package com.eqdd.yiqidian.ui.discover.makerspace

import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector
import com.eqdd.yiqidian.base.Config
import com.eqdd.yiqidian.bean.rebuild.LearnMineInfo
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHtmlBean
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditIconBean
import com.eqdd.yiqidian.http.DialogCallBack
import com.eqdd.yiqidian.http.HttpConfig
import com.eqdd.yiqidian.http.HttpResult
import com.eqdd.yiqidian.kotlin.BaseInfoActivity
import com.gamerole.richtextview.RichEditor
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import java.util.*

/**
 * Created by jhj on 18-8-15.
 */
class MakerPersonalActivity : BaseInfoActivity() {
    override val topbar: String
        get() = "个人信息"


    private var bean: LearnMineInfo? = null


    override fun initData() {
        super.initData()
        val makerGuid = intent?.getStringExtra(Config.GUID)
        OkGo.post<HttpResult<LearnMineInfo>>(HttpConfig.BASE_URL + HttpConfig.LEARN_MINE_INFO)
                .params("userGuid", makerGuid)
                .execute(object : DialogCallBack<HttpResult<LearnMineInfo>>(this) {
                    override fun onSuccess(response: Response<HttpResult<LearnMineInfo>>) {
                        val httpResult = response.body()
                        if (httpResult.status == 200) {
                            bean = httpResult.items
                            setEditBeans()
                            slimAdapterEx.notifyDataSetChanged()
                        }
                    }
                })
    }


    override fun itemClick(p: Int) {

    }

    override fun setEditBeans() {
        datas.clear()
        val url = if (bean?.qualifications?.endsWith(";") == true) {
            HttpConfig.BASE_URL + bean?.qualifications?.substring(0, bean?.qualifications?.indexOf(";")
                    ?: 0)
        } else {
            HttpConfig.BASE_URL + bean?.qualifications
        }

        datas.add(SlimEditIconBean("头像", bean?.headimage, 0))
        datas.add(SlimEditHintBean("姓名", bean?.realname, 1))
        datas.add(SlimEditHintBean("手机", bean?.phone, 2))
        datas.add(SlimEditHintBean("助理手机", bean?.assistantPhone, 3))
        datas.add(SlimEditHintBean("助理姓名", bean?.assistant, 4))
        datas.add(SlimEditHintBean("邮箱", bean?.email, 5))
        datas.add(SlimEditHintBean("QQ", bean?.qq, 6))
        datas.add(SlimEditHintBean("微信", bean?.wechat, 7))
        datas.add(SlimEditHintBean("常驻地址", bean?.address, 8))
        datas.add(SlimEditHintBean("研究领域", bean?.researchField, 9))
        datas.add(SlimEditHintBean("课程价格(元/天)", String.format(Locale.CHINA, "%.2f元/天", bean?.cooperativePrice), 10))
        datas.add(SlimEditHintBean("课程", bean?.courses, 11))
        datas.add(SlimEditHintBean("授课风格", bean?.teachStyle, 12))
        datas.add(SlimEditIconBean("个人资质", url, 13).setCircle(false))
        datas.add(SlimEditHtmlBean("讲师简介", bean?.lecturerBackground?.replace("\\", ""), 14))
        datas.add(SlimEditHtmlBean("客户案例", bean?.custCase?.replace("\\", ""), 15))
        datas.add(SlimEditHtmlBean("曾服务过的企业", bean?.serviceCom?.replace("\\", ""), 16))
        slimAdapterEx.register<SlimEditHtmlBean>(R.layout.list_item_177, SlimInjector<SlimEditHtmlBean> { data, injector ->
            injector?.text(R.id.tv_label, data?.title)
                    ?.with<RichEditor>(R.id.richEditor) {
                        val html = data?.content
                                ?.replace("<pre>", "")
                                ?.replace("</pre>", "")
                        it.setPadding(10, 0, 10, 0)
                        it.html = html
                    }
        })
    }


}